package day04;

import java.util.ArrayList;
import java.util.Random;

public class Manager extends User {
	public Manager(){
	}
	public Manager(String name,int money){
		super(name,money);
	}
	//发红包
	public ArrayList<Integer> send(int totalMoney,int count){
		ArrayList<Integer> redList=new ArrayList<Integer>();
		//首先群主要看自己的钱
		int lefMoney = super.getMoney();
		if(totalMoney>lefMoney){
			System.out.println("余额不足");
			return redList;
		}
		//扣钱
		super.setMoney(lefMoney-totalMoney);
		int last=totalMoney;
		//把红包放到集合里面
		for (int i = 0; i <4; i++) {
			//发红包需要平均拆分成count份
			int avg=last/count;
			int mony = new Random().nextInt(avg*2);
			if(mony<=last&&mony>0) {
				redList.add(mony);
				last=last-mony;//剩余多少钱
				count-=1;
			}
		}
		//最后一个红包
		redList.add(last);
		return redList;
	}
 }